package structure
{
	import flash.events.EventDispatcher;
	import flash.utils.Dictionary;
	[Event(name="complete", type="structure.DictionaryAndArrayEvent")]
	public class DictionarySingle extends EventDispatcher
	{
		private var dictionary:Dictionary;
		private var _length:int=0;
		public function DictionarySingle()
		{
			dictionary=new Dictionary();
		}
		/**
		 * 设置数值，并保持数值唯一
		 */ 
		public function addValue(key:String,value:Object):Boolean
		{
			if(dictionary[key]==null)
			{
				dictionary[key]=value;
				_length++;
				return true;
			}
			return false;
		}
		/**
		 * 设置数据里面的内容,并抛出事件
		 */ 
		public function setContent(key:String,content:*):void
		{
			if(dictionary[key]!=null)
			{
				dictionary[key]["content"]=content;
				var e:DictionaryAndArrayEvent=new DictionaryAndArrayEvent(DictionaryAndArrayEvent.COMPLETE);
				e.key=key;
				this.dispatchEvent(e);
			}
		}
		/**
		 * 获取指定的内容
		 */ 
		public function getContent(key:String):*
		{
			return dictionary[key]["content"];
		}
		/**
		 * 删除指定的数据
		 */ 
		public function removeValue(key:*):void
		{
			if(dictionary[key]!=null)
			{
				dictionary[key]=null;
				_length--;
			}
		}
		/**
		 * 获取当前数据的个数
		 */ 
		public function get length():int
		{
			return _length;
		}
		/**
		 * 回收内存
		 */ 
		public function dispose():void
		{
			dictionary=null;
			_length=0;
		}
	}
}